// CircualProgress.cpp: implementation of the CCircualProgress class.
//
//////////////////////////////////////////////////////////////////////

#include "CircularProgress.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CircularProgress::CircularProgress(double &_prog, Colour _fColour) : progress (_prog), fColour(_fColour)
{
	oldProgress = progress = 0;
	fColour = Colours::red;
	fontFColour = Colours::white;
	bColour = Colours::white.withAlpha (0.0f);
	startTimer (250);
}

CircularProgress::~CircularProgress()
{
	progress = 0;
}

void CircularProgress::paint(Graphics &g)
{	
	if (progress > 100)
	{
		internalProgress = 100;
	}
	else
	{
		internalProgress = progress;
	}

	Path p;
	float slice = 0;
	
	g.fillAll (bColour);
	g.setColour (fColour);

	for (int k=0; k<(internalProgress/2); k++)
	{
		p.addArc (8, 8, (float)getWidth()-16, (float)getHeight()-16, (float)slice, (float)slice+(float)SLICE, true);
		slice = slice + ((float)SLICE*2);
	}

	g.setColour (fontFColour);
	g.setFont ((float)(getHeight()/6), Font::bold);
	g.drawSingleLineText  (String::formatted (T("%.0f%%"), internalProgress), (getWidth()/2)-16, getHeight()/2+4);

	g.setColour (fColour);
	g.strokePath (p, PathStrokeType (16.0f));
}

void CircularProgress::colourChanged()
{
	fColour		= findColour (ProgressColour);
	fontFColour = findColour (FontColour);
	bColour		= findColour (BackgroundColour);
}

void CircularProgress::timerCallback()
{
	repaint();
}

void CircularProgress::resized()
{
	Logger::writeToLog (String::formatted (T("progress resize %d %d"), getWidth(), getHeight()));
}